/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler;

import bbd.crawler.media.GoogleCustomSearch;
import bbd.crawler.media.Scheduler;
import bbd.crawler.util.Console;
import java.text.DateFormat;
import java.util.Date;

/**
 *
 * @author Harit
 */
public class MediaCrawl {

    public static final String ARTIST = "Metallica";
    
    private static final String GOOGLE_QUERY_SPACE_CHAR = "%20";
    private static final String REPLACE_WITH_SPACE = " ";
    //--------------------------------------------------------------------------
    /** Javadoc here */
    public MediaCrawl () {

    } // end default constructor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static void main1 ( String args [] ) {

        Scheduler instance = Scheduler.getInstance();

        if ( instance == null ) { System.out.println("instance null"); }

        instance.crawl("metallica");

    } // end main method

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public static void main ( String args[] ) {

        String responseData = null;

        System.out.println("crawling music now ..");

        GoogleCustomSearch.setQuery( ARTIST );
        
        GoogleCustomSearch.setQueryString( ARTIST.replaceAll( GOOGLE_QUERY_SPACE_CHAR, REPLACE_WITH_SPACE) );

        responseData = GoogleCustomSearch.query();

        if ( responseData == null ) {

            Console.error( "MediaCrawl.main",  "search returned null data - exiting ");

            System.exit(-1);
            
        }

        /* Keeping track of total time */
        DateFormat df = DateFormat.getInstance();

        Date startTime = new Date();

        GoogleCustomSearch.processGoogleResults( responseData );

        GoogleCustomSearch.findMediaUrls();

        Date endTime = new Date();

        System.out.println("Start time : " + df.format( startTime ) );
        System.out.println("Start time : " + df.format( endTime ) );
        System.out.println("Time taken : " + ( ( endTime.getTime() - startTime.getTime() )/(1000 * 60) ) );
        
    } // end of test method

} // end class MediaCrawl
